package com.example.zzm.yuejian03.Model;

import com.example.zzm.yuejian03.Bean.TrainBean;
import com.example.zzm.yuejian03.Iface.TraindetailsIface;
import com.example.zzm.yuejian03.Listener.TListener;
import com.example.zzm.yuejian03.Server;
import com.example.zzm.yuejian03.Service.Service;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class TrainModeldetails implements TraindetailsIface {

    private Retrofit retrofit;


    public TrainModeldetails(){
        retrofit=new Retrofit.Builder()
                .baseUrl(Server.BASEURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();

    }
    @Override
    public void getTraindetailss(int train_id,final TListener listener) {
        Service service
                =retrofit.create(Service.class);
        Call<TrainBean> call
                =service.getTraindetails(train_id);


        call.enqueue(new Callback<TrainBean>() {
            @Override
            public void onResponse(Call<TrainBean> call, Response<TrainBean> response) {
                if(response.isSuccessful() && response!=null)
                {  listener.onResponse(response.body());
                }
                else   listener.onFail("on response fail");
            }
            @Override
            public void onFailure(Call<TrainBean> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });

    }
}
